package output;


import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import calendar.Calendar;

/**
 * @author Monika
 * 
 * Goal: Rewrite information from old user profile file to new file, 
 * with replacing all old Events of tense "Possible" with the
 * events retrieved from Google Calendar, based on the google cal url
 * stored in the user profile file.
 * 
 * My general approach in both parsers:
 * 
 * I read the input file line by line and rewrite it to output file. Some part
 * of input file (old events) I ignore, some part (new events) I write
 * to output file from the data which I got from GoogleAPIDataProvider. 
 * 
 * For each line I check whether it is a start of new entity,
 * a middle of existing entity, or end of entity. I also remember what entity 
 * it is currently.
 * 
 * (When I see the "Calendar" entity I set the calendarID of the calendar,
 * based on what I read from the file.) 
 * 
 * After "Calendar" entity is finished, I know that next come the Events. 
 * So right after "Calendar" is finished I output new events from Google. 
 * After that I output all things except the Events that are marked as "Possible".
 * 
 * Some events are spread across the lines, so I use boolean variables,
 * or temporary String variables to determine which parts are to be
 * ignored and which are not.
 * 
 * The comments are being rewritten without change, so they are not affected.
 *
 */
public abstract class Parser {
	
	protected BufferedWriter out;
	
	public void writeLine(String originalLine) {
		try{
			out.write(originalLine);
			out.write("\n");
		}catch(IOException e){
			e.printStackTrace();
		}
	}	
	
	/**
	 * Gets user calendar public url from user profile file
	 * @param filename
	 * @return
	 */
	public abstract String getUserCalUrlFromFile(String filename);

	/**
	 * Returns java regex for filename pattern
	 * @return
	 */
	public abstract String getFilenamePattern();

	/**
	 * file + calendar = outfile ;)
	 * @param filename
	 * @param calendar
	 * @param outfilename
	 */
	public abstract void writeCalendarData(String filename, Calendar calendar, String outfilename) ;	
	
}
